package com.tledu.zyf.service.impl;

import java.util.List;

import com.tledu.zyf.dao.IGroupDao;
import com.tledu.zyf.model.Group;
import com.tledu.zyf.service.IGroupService;
import com.tledu.zyf.util.ERPException;
import com.tledu.zyf.util.ObjectFactory;

public class GroupService implements IGroupService {

	private IGroupDao groupDao = ObjectFactory.getGroupDao();

	@Override
	public List<Group> list() {
		return groupDao.list();
	}

	@Override
	public void add(Group group) {
		groupDao.add(group);
	}

	@Override
	public boolean verifyGroupname(String groupname) {
		Group group = groupDao.loadByGroupname(groupname);
		if (group == null) {
			return false;
		}
		return false;
	}

	@Override
	public void delete(int id) throws ERPException {
		// 根据部门 ID 去 t_user 表中进行查询 count(*) 如果大于 0 ,说明该部门下还有员工
		int count = ObjectFactory.getUserDao().loadByGroupId(id);
		if (count > 0) {
			throw new ERPException("该部门下还有员工,不能删除哦~");
		}
		groupDao.delete(id);
	}

	@Override
	public Group load(int id) {
		return groupDao.load(id);
	}

	@Override
	public void update(Group group) {
		groupDao.update(group);
	}

	@Override
	public List<Group> vagueUsername(String groupname) {
		return groupDao.vagueGroupname(groupname);
	}

}
